<template>
  <div>
    <div v-for="item in dataList" :key="item._id" class="box" @click="detail(item)">
      <div v-if="item.recImage.length === 1">
        <img
          v-for="(items, index) in item.recImage"
          :key="index"
          class="img1"
          :src="items"
          alt="暂无图片"
        />
      </div>
      <div v-else-if="item.recImage.length === 2 || item.recImage.length === 4">
        <img
          v-for="(items, index) in item.recImage"
          :key="index"
          class="img2"
          :src="items"
          alt="暂无图片"
        />
      </div>
      <div v-else-if="item.recImage.length === 3">
        <img
          v-for="(items, index) in item.recImage"
          :key="index"
          class="img3"
          :src="items"
          alt="暂无图片"
        />
      </div>
      <div v-else-if="item.recImage.length === 5 || item.recImage.length === 8">
        <img
          v-for="(items, index) in item.recImage"
          :key="index"
          class="img5"
          :src="items"
          alt="暂无图片"
        />
      </div>
      <div v-else-if="item.recImage.length === 6 || item.recImage.length === 9">
        <img
          v-for="(items, index) in item.recImage"
          :key="index"
          class="img6"
          :src="items"
          alt="暂无图片"
        />
      </div>
      <div v-else-if="item.recImage.length === 7">
        <img
          v-for="(items, index) in item.recImage"
          :key="index"
          class="img7"
          :src="items"
          alt="暂无图片"
        />
      </div>
      <div class="topic">{{item.rectopic}}</div>
      <div class="foot">
        <van-image
          style="transform: translateY(-15px)"
          width="25px"
          height="25px"
          round
          :src=" item.avatar || 'https://img01.yzcdn.cn/vant/cat.jpeg'"
        />
        <span>{{item.username}}</span>
        <span>
          <van-icon :name="'like-o'" size="16px" :color="'#999999'" @click="changelike"></van-icon>
          <span
            style="display: inline-block;margin-left: 5px; color: #999999;font-size: 14px; transform:translateY(-2px)"
          >{{item.likeCount}}</span>
        </span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    dataList: {
      type: Array,
      default: [],
      likeFlag: false
    }
  },
  data() {
    return {};
  },
  methods: {
    detail(item) {
      console.log(item);
      this.$router.push({ name: "recommenddetail", params: { id: item._id } });
    },
    changelike() {
      // this.likeFlag = !this.li
      console.log(111);
    }
  }
};
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
}
.box {
  background-color: #fff;
  box-shadow: 0px 0px 2px #bbb;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 2px;
}
.box div {
  clear: both;
}
.img1 {
  width: 100%;
  height: 160px;
}
.img2 {
  width: 100%;
  height: 120px;
  float: left;
}
.img3 {
  width: 50%;
  height: 100px;
  float: left;
}
.img3:first-child {
  width: 100%;
  height: 100px;
}
.img5 {
  width: 33.3%;
  height: 60px;
}
.img5:nth-child(-n + 2) {
  width: 50%;
  height: 100px;
}
.img6 {
  width: 33.3%;
  height: 60px;
}
.img7 {
  width: 33.3%;
  height: 60px;
}
.img7:first-child {
  width: 100%;
  height: 90px;
}
.topic {
  padding: 10px 0 0 5px;
  font-size: 16px;
  height: 50px;
}
.foot {
  height: 30px;
  line-height: 30px;
  padding: 5px;
}

.foot > span {
  display: inline-block;
  padding: 5px;
  transform: translateY(-6px);
}
.foot > span:nth-child(2) {
  max-width: 72px;
  display: inline-block;
  color: #999999;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.foot > span:last-child {
  transform: translateY(-3px);
  float: right;
  padding: 5px 5px 0 0;
}
</style>